Skip to content

fix(lib-std-fs): handle usize overflow in read* #143462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rudxain
Copy link
Contributor

@Rudxain Rudxain commented Jul 4, 2025

I assume this is a non-breaking change, as there would be an OOM panic anyways. This patch ensures a fast-fail when there's not enough memory to load the file. This only changes behavior on platforms where usize is smaller than 64bits

@rustbot
Copy link
Collaborator

rustbot commented Jul 4, 2025

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 4, 2025
@rust-log-analyzer

This comment has been minimized.

@a1phyr
Copy link
Contributor

a1phyr commented Jul 5, 2025

Shouldn't this fail with ErrorKind::OutOfMemory directly instead?

Also modifications to fs::read_to_string should be made to fs::read too, as they are essentially the the function.

@Rudxain Rudxain force-pushed the read_to_string_usize branch 2 times, most recently from c72c762 to c03b767 Compare July 5, 2025 22:06
@Rudxain Rudxain changed the title fix(lib-std-fs): handle usize overflow in read_to_string fix(lib-std-fs): handle usize overflow in read* Jul 5, 2025
@Rudxain Rudxain force-pushed the read_to_string_usize branch from c03b767 to a320810 Compare July 5, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants